﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using DotNet.Extensions;
using DotNet.Mvc;
using XNWebModel;
using XNWebService;

namespace XNWebAPI.Controllers
{
    public class NewsApiController : JsonController
    {
        public ActionResult NewsCategory()
        {
            var dicService = new SystemDictionaryService();
            var details = dicService.GetDetails("NewsCategory");
            var data = details.Select(p => new { id = p.Value, name = p.Name,sortIndex=p.SortIndex }).OrderBy(p=>p.sortIndex).ToList();
            return Json(new
            {
                succ = "1",
                count = data.Count,
                msg = string.Empty,
                data
            });
        }

        public ActionResult NewsDetails(string id)
        {
            var entity = NewsService.Instance.Get(id.ToInt()) ?? new News();
            var data = new { entity.Id, entity.Title, entity.Details, entity.CreateDateTime };
            return Json(new
            {
                succ = "1",
                count = 1,
                msg = string.Empty,
                data
            });
        }

        public ActionResult NewsList(string page, string category, string size = "10")
        {
            var details = NewsService.Instance.GetAppPageList(page.ToInt(), size.ToInt(), category);
            var data = details.Select(p => new { p.Id, p.Title, p.CreateDateTime }).ToList();
            return Json(new
            {
                succ = "1",
                count = data.Count,
                msg = string.Empty,
                data
            });
        }
    }
}